package kitwee.com.kanpad.orderDetail;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.blankj.utilcode.util.LogUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import kitwee.com.kanpad.BaseFragment;
import kitwee.com.kanpad.R;
import kitwee.com.kanpad.bean.BomAdapter;
import kitwee.com.kanpad.bean.ListDetailBean;
import kitwee.com.kanpad.bean.MessageAdapter;

/**
 * @author GanQuan
 * @date 2018/1/22
 */

public class MessageFragment extends BaseFragment {

    @BindView(R.id.message)
    RecyclerView message;

    private View layout;
    private MessageAdapter messageAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        layout = inflater.inflate(R.layout.message_fragment_layout, container, false);
        ButterKnife.bind(this, layout);
        return layout;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
    }

    private List<ListDetailBean.KanbanMessageVOListBean> messageList;
    private void initView() {
        messageList = new ArrayList<>();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        message.setLayoutManager(linearLayoutManager);
        messageAdapter = new MessageAdapter(getActivity(),messageList);
        message.setAdapter(messageAdapter);
    }

    public static MessageFragment newInstance() {
        return new MessageFragment();
    }


    @Override
    public void onStop() {
        super.onStop();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void onStart() {
        super.onStart();
        EventBus.getDefault().register(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onShowMessageEvent(OrderDetailEvent orderDetailEvent){
        LogUtils.e("消息 : " + orderDetailEvent.getListDetailBean().getKanbanMessageVOList());
//        List<ListDetailBean.KanbanMessageVOListBean> kanbanMessageVOList = orderDetailEvent.getListDetailBean().getKanbanMessageVOList();
//        if(kanbanMessageVOList!=null&&kanbanMessageVOList.size()>0){
//            messageList.clear();
//            messageList.addAll(kanbanMessageVOList);
//            messageAdapter.notifyDataSetChanged();
//        }


    }
}
